MODULE XLTLgeomobj; (** AUTHOR "fnecati"; PURPOSE "Adjusted for commandline run"; *)

IMPORT
	XLTLBase, GL:=OpenGL, GLU,  GLC := OpenGLConst, XLTLGL,  Random;

TYPE 
	Voxel=XLTLBase.Voxel;
	PT=XLTLBase.PT;

TYPE gobj*=OBJECT(XLTLBase.V)
VAR
	dlist*: LONGINT;
	rot, drot: REAL;
	
PROCEDURE tick*;
BEGIN
	rot:=rot+drot;
END tick;	
	
PROCEDURE draw*(p: PT; scale: LONGINT; rot: REAL);
BEGIN
	XLTLGL.dlpush(p,scale,rot,dlist); 
END draw;
	
END gobj;


TYPE pcursor*=OBJECT(gobj)

PROCEDURE &init*;
VAR
	i:LONGINT;
	p,n,center: PT;
	r: REAL;
BEGIN
	center.x:=0; center.y:=0; center.z:=0;

	dlist:=GL.GenLists(1);
	GL.NewList(dlist, GLC.GL_COMPILE); 
	GL.Disable(GLC.GL_LIGHTING); 
	GL.PointSize(3);
	GL.Begin( GLC.GL_POINTS);	
	GL.Color3f(0.0,0.0,0.0);
	FOR i:=0 TO 50 DO	
		r:=i/49-1/2;
		GL.Vertex3f(r,0,0);
	END;
	FOR i:=0 TO 50 DO	
		r:=i/49-1/2;
		GL.Vertex3f(0,0,r);	
	END;
	FOR i:=0 TO 50 DO	
		r:=i/49-1/2;
		GL.Vertex3f(0,r,0);	
	END;	
	GL.Color3f(1.0,1.0,1.0);
	FOR i:=0 TO 50 DO	
		r:=i/49-1/2+1/100;
		GL.Vertex3f(r,0,0);
	END;
	FOR i:=0 TO 50 DO	
		r:=i/49-1/2+1/100;
		GL.Vertex3f(0,0,r);	
	END;
	FOR i:=0 TO 50 DO
		r:=i/49-1/2+1/100;
		GL.Vertex3f(0,r,0);	
	END;		
	GL.End();
	GL.EndList();	
END init;

END pcursor;

TYPE psphere*=OBJECT(gobj)

PROCEDURE &init*;
VAR
	i:LONGINT;
	p,n,center: PT;
	r: REAL;
BEGIN
	center.x:=0; center.y:=0; center.z:=0;
	dlist:=GL.GenLists(1);
	GL.NewList(dlist, GLC.GL_COMPILE); 
	GL.Disable(GLC.GL_LIGHTING);	
	GL.PointSize(10);
	GL.Begin( GLC.GL_POINTS);	
	GL.Color3f(1.0,0.0,0.0);
	FOR i:=0 TO 50 DO	
		p:=XLTLBase.randPT();
		GL.Vertex3f(p.x,p.y,p.z);
	END;
(*	FOR i:=0 TO 50 DO	
		GL.DelFCR();
		XLTLBase.randsphPT(p,n,center,1/2);
		GL.SetFCR();
		GL.Vertex3f(p.x,p.y,p.z);
	END;
	GL.Color3f(0.0,1.0,0.0);
	FOR i:=0 TO 50 DO	
		GL.DelFCR();
		XLTLBase.randsphPT(p,n,center,1/2);
		GL.SetFCR();
		GL.Vertex3f(p.x,p.y,p.z);
	END;
	GL.Color3f(0.0,0.0,1.0);
	FOR i:=0 TO 50 DO	
		GL.DelFCR();
		XLTLBase.randsphPT(p,n,center,1/2);
		GL.SetFCR();
		GL.Vertex3f(p.x,p.y,p.z);
	END;
*)	
	GL.End();
	GL.EndList();	
END init;

END psphere;

TYPE sphere*=OBJECT(gobj)
VAR
	qObj: GLU.QuadricObj;
		
PROCEDURE & init*;

BEGIN
	dlist:=GL.GenLists(1);
	qObj := GLU.NewQuadric();
	GLU.QuadricCallback(qObj, GLU.GLU_TESS_ERROR, 0 );
	GLU.QuadricDrawStyle(qObj, GLU.GLU_FILL); 
	GLU.QuadricNormals(qObj, GLU.GLU_SMOOTH);
	GL.NewList(dlist, GLC.GL_COMPILE);
		GLU.Sphere(qObj, 0.7, 15, 15);
	GL.EndList();	
END init;
	
END sphere;

VAR
	rand*:Random.Generator;


BEGIN
	NEW(rand)
END XLTLgeomobj.

